// Copyright©,2020-2025
// Author: caocheng
// Version: 1.0.0
// Date: 2021/3/2 14:23
// Description：
package SummerBoot

import (
	"fmt"
	"strings"

	"github.com/labstack/gommon/color"
)

// defaultBanner 默认的 Banner 字符
const defaultBanner = `
 _______  _______         _______           _______  _______  _______  _______ 
(  ____ \(  ___  )       (  ____ \|\     /|(       )(       )(  ____ \(  ____ )
| (    \/| (   ) |       | (    \/| )   ( || () () || () () || (    \/| (    )|
| |      | |   | | _____ | (_____ | |   | || || || || || || || (__    | (____)|
| | ____ | |   | |(_____)(_____  )| |   | || |(_)| || |(_)| ||  __)   |     __)
| | \_  )| |   | |             ) || |   | || |   | || |   | || (      | (\ (   
| (___) || (___) |       /\____) || (___) || )   ( || )   ( || (____/\| ) \ \__
(_______)(_______)       \_______)(_______)|/     \||/     \|(_______/|/   \__/
`

// version 版本信息
const version = `go-summer@v1.0.0`

type BannerMode int

const (
	BannerModeOff     BannerMode = 0
	BannerModeConsole BannerMode = 1
)

// customBanner 自定义 Banner 字符串
var customBanner = ""

// SetBanner 设置自定义 Banner 字符串
func SetBanner(banner string) {
	customBanner = banner
}

// printBanner 打印 Banner 到控制台
func printBanner(banner string) {

	// 确保 Banner 前面有空行
	if banner[0] != '\n' {
		fmt.Println()
	}

	maxLength := 0
	for _, s := range strings.Split(banner, "\n") {
		fmt.Println(color.Cyan(s))
		if len(s) > maxLength {
			maxLength = len(s)
		}
	}

	// 确保 Banner 后面有空行
	if banner[len(banner)-1] != '\n' {
		fmt.Println()
	}

	var padding []byte
	if n := (maxLength - len(version)) / 2; n > 0 {
		padding = make([]byte, n)
		for i := range padding {
			padding[i] = ' '
		}
	}
	fmt.Println(string(padding) + version + "\n")
}